package com.longtop.framework.sys.login.web;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.longtop.framework.base.BaseAction;
import com.longtop.framework.base.BaseService;
import com.longtop.framework.common.Constant;
import com.longtop.framework.security.SessionObject;
import com.longtop.framework.sys.homeCustom.model.TSysHomeCustom;
import com.longtop.framework.util.SpringBeanFactory;
import com.longtop.intelliweb.action.IInitContext;
import com.longtop.intelliweb.view.Panel;

/**
 * 
 * @author 胡砥峰
 * @version 1.0
 */
public class WelcomeAction extends BaseAction {

	/**
	 * 系统共用：初始化调用
	 */
	public void init(IInitContext context) {
		super.init(context);
	}

	/**
	 * 本页jsp：初始化业务数据(覆写父类方法)
	 */
	public void thisPageInit(IInitContext context) {

		// 调用spring的业务逻辑
		BaseService baseService = SpringBeanFactory.getBean(BaseService.BEAN_ID);
		SessionObject sessionObject = this.getSessionObject(context);

		try {
			List homeCustomList = baseService.queryAll("from TSysHomeCustom where roleId='" + sessionObject.getRoleId() + "' and userId='" + sessionObject.getUserId() + "' order by sortNo asc");
			if (homeCustomList == null || homeCustomList.size() == 0) {
				homeCustomList = baseService.queryAll("from TSysHomeCustom where roleId='" + "admin" + "' and userId='" + Constant.ADMIN + "' order by sortNo asc");
			}
			for (int i = 0; i < homeCustomList.size(); i++) {
				// 只取4个
				if (i > 3)
					break;

				TSysHomeCustom sysHomeCustom = (TSysHomeCustom) homeCustomList.get(i);

				Panel panel = (Panel) context.getControl("Panel" + (i + 1));
				String path = sysHomeCustom.getFuncUrl() + "?chartType=" + StringUtils.trimToEmpty(sysHomeCustom.getChartType());
				panel.setPath(path);
				panel.setCaption(sysHomeCustom.getFuncName());
			}
		} catch (Exception e) {
		}
	}
}
